package com.pimee.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import com.pimee.common.config.UbConfig;
import com.pimee.common.util.shiro.ShiroUtils;
import com.pimee.model.SysUser;
import com.pimee.model.vo.SysMenuVo;
import com.pimee.model.vo.SysUserVo;
import com.pimee.service.admin.ISysMenuService;
import com.pimee.service.admin.ISysUserService;

import io.swagger.annotations.ApiOperation;

/**
 * 首页 业务处理
 * 
 * @description
 * @author Bruce Shaw 2020年2月10日 下午5:34:31
 */
@Controller
public class IndexController extends AbstractController {
	@Autowired
	private ISysMenuService sysMenuService;
	@Autowired
	private ISysUserService sysUserService;
	@Autowired
	private UbConfig ubConfig;

	// 系统首页
	@ApiOperation("进入系统首页")
	@GetMapping("admin/index")
	public String index(ModelMap modelMap) {
		// 取身份信息
		SysUser user = ShiroUtils.getSysUser();
		// 根据用户id取出菜单
		List<SysMenuVo> menus = sysMenuService.selectMenusByUser(user);
		SysUserVo userVo = sysUserService.selectUserById(user.getUserId());
		modelMap.put("menus", menus);
		modelMap.put("user", userVo);
		modelMap.put("copyrightYear", ubConfig.getCopyrightYear());
		modelMap.put("demoEnabled", ubConfig.isDemoEnabled());

		return "admin/index";
	}

	// 切换主题
	@GetMapping("/admin/sys/switchSkin")
	public String switchSkin(ModelMap modelMap) {
		return "admin/skin";
	}

	// 系统介绍
	@GetMapping("/system/main")
	public String main(ModelMap mmap) {
		mmap.put("version", "4.01");
		return "admin/main_v1";
	}
}
